﻿// ******************************************************************
// * Copyright(c)  Steven Lu
// * Description   : Entity_MST_SIGNATURE_ATTACHED
// * CreateDate    : 2012/2/27 14:23:29
// * Creater       : CodeSmith
// * LastChangeDate: 2012/2/27 14:23:29
// * LastChanger   : 2012/2/27 14:23:29
// * Version Info  : 1.0 For ESOL
// ******************************************************************

using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Suzsoft.Smart.Data;
using ESOL.Common.Entity;
using ESOL.Common;

namespace ESOL.Business.Mst
{
    /// <summary>
    /// MstSignatureAttached
    /// </summary>
    public partial class MstSignatureAttachedBs
    {
        #region GetByID
        /// <summary>
        /// Get Entity
        /// </summary>
        /// <param name="objMstSignatureAttachedEntity">Entity</param>
        /// <returns>Entity</returns>
        public static MstSignatureAttachedEntity GetMstSignatureAttached(MstSignatureAttachedEntity objMstSignatureAttachedEntity)
        {
            return DataAccess.SelectSingle<MstSignatureAttachedEntity>(objMstSignatureAttachedEntity);
        }
        #endregion


        #region Insert
        /// <summary>
        /// Insert Data
        /// </summary>
        /// <param name="objMstSignatureAttachedEntity">Entity</param>
        /// <returns>true Insert Succeed; false Insert Fail</returns>
        public static bool InsertMstSignatureAttached(MstSignatureAttachedEntity objMstSignatureAttachedEntity)
        {
            return DataAccess.Insert(objMstSignatureAttachedEntity);
        }

        public static bool InsertMstSignatureAttached(List<MstSignatureAttachedEntity> objMstSignatureAttachedEntityList)
        {
            return DataAccess.Insert(objMstSignatureAttachedEntityList);
        }
        #endregion


        #region Update
        /// <summary>
        /// Update Data
        /// </summary>
        /// <param name="objMstSignatureAttachedEntity">Entity</param>
        /// <returns>true Update Succeed; false Update Fail</returns>
        public static bool UpdateMstSignatureAttached(MstSignatureAttachedEntity objMstSignatureAttachedEntity)
        {
            return DataAccess.Update(objMstSignatureAttachedEntity);
        }

        public static bool UpdateMstSignatureAttached(List<MstSignatureAttachedEntity> objMstSignatureAttachedEntityList)
        {
            return DataAccess.Update<MstSignatureAttachedEntity>(objMstSignatureAttachedEntityList);
        }
        #endregion


        #region Delete
        /// <summary>
        /// Delete Data
        /// </summary>
        /// <param name="objMstSignatureAttachedEntity">Entity</param>
        /// <returns>true Delete Succeed; false Delete Fail</returns>
        public static bool DeleteMstSignatureAttached(MstSignatureAttachedEntity objMstSignatureAttachedEntity)
        {
            return DataAccess.Delete(objMstSignatureAttachedEntity);
        }

        public static bool DeleteMstSignatureAttached(List<MstSignatureAttachedEntity> objMstSignatureAttachedEntityList)
        {
            return DataAccess.Delete<MstSignatureAttachedEntity>(objMstSignatureAttachedEntityList);
        }
        #endregion


        #region GetAll
        /// <summary>
        /// Get All Data
        /// </summary>
        /// <returns>Back All Data<returns>
        public static DataSet GetMstSignatureAttachedAll()
        {
            return DataAccess.SelectAllDataSet<MstSignatureAttachedEntity>();
        }
        /// <summary>
        /// Get All Data List
        /// </summary>
        /// <returns>Back All Data List<returns>
        public static List<MstSignatureAttachedEntity> GetMstSignatureAttachedAllList()
        {
            return DataAccess.SelectAll<MstSignatureAttachedEntity>();
        }
        #endregion

        #region Functions
        public static MstSignatureAttachedEntity GetSignatureAttchedByPersonID(string PersonID)
        {
            string Sql="select * from MST_SIGNATURE_ATTACHED where person_id='"+PersonID+"' ";
            List<MstSignatureAttachedEntity> list = DataAccess.Select<MstSignatureAttachedEntity>(Sql);
            if (list != null && list.Count > 0)
            {
                return list[0];
            }
            else return null;
        }

        public static bool SaveListSignatureAttached(List<MstSignatureAttachedEntity> list)
        {
            using (DataAccessBroker broker = DataAccessFactory.Instance())
            {
                try
                {
                    broker.BeginTransaction();
                    DataAccess.Insert(list, broker);
                    broker.Commit();
                    return true;
                }
                catch (Exception ex)
                {
                    broker.RollBack();
                    throw ex;
                }
            }
        }

        public static DataTable GetDtByCondition(string rowCount, string Condition, string OrderBy)
        {
            string Sql = CommonFunctions.GetSelect(rowCount) + @" MSA.SIGNATURE_ID,MSA.PERSON_ID,MSA.FILE_NAME,
                MP.NAME_CN,MP.PERSON_CODE,
                MP.DEPARTMENT_ID,MD.DEPARTMENT_NAME
                FROM MST_SIGNATURE_ATTACHED MSA
                LEFT JOIN MST_PERSON MP ON MSA.PERSON_ID=MP.PERSON_ID
                LEFT JOIN MST_DEPARTMENT MD ON MP.DEPARTMENT_ID=MD.DEPARTMENT_ID WHERE 1=1 ";
            if (!string.IsNullOrEmpty(Condition))
                Sql += Condition;
            if (!string.IsNullOrEmpty(OrderBy))
                Sql += OrderBy;
            DataSet ds = DataAccess.SelectDataSet(Sql);
            if (ds != null && ds.Tables[0] != null)
                return ds.Tables[0];
            else return null;
        }
        #endregion
    }


}

